/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;
import model.Student;
import model.Course;
import dao.StudentSystemDao;
import dao.StudentSystemDaoJDBCImpl;
import javax.swing.JOptionPane;

/**
 *
 * @author Lenovo
 */
public class UpdataFrame extends javax.swing.JFrame {

    /**
     * Creates new form UpdataFrame
     */
    public UpdataFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        classroom = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        id = new javax.swing.JFormattedTextField();
        jButton1 = new javax.swing.JButton();
        room = new javax.swing.JRadioButton();
        ageButton = new javax.swing.JRadioButton();
        nameButton = new javax.swing.JRadioButton();
        javaButton = new javax.swing.JRadioButton();
        mathButton = new javax.swing.JRadioButton();
        sportButton = new javax.swing.JRadioButton();
        stuClass = new javax.swing.JFormattedTextField();
        nameText = new javax.swing.JFormattedTextField();
        mathText = new javax.swing.JFormattedTextField();
        sportText = new javax.swing.JFormattedTextField();
        ageText = new javax.swing.JFormattedTextField();
        javaText = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        classroom.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setText("请输入要修改学生的id");

        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setText("确定");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        room.setText("班级");

        ageButton.setText("年龄");

        nameButton.setText("姓名");

        javaButton.setText("Java成绩");

        mathButton.setText("数学成绩");
        mathButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mathButtonActionPerformed(evt);
            }
        });

        sportButton.setText("体育成绩");

        jLabel2.setText("请选择要修改的对象并填入修改信息");

        jButton2.setBackground(new java.awt.Color(255, 255, 255));
        jButton2.setText("返回");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout classroomLayout = new javax.swing.GroupLayout(classroom);
        classroom.setLayout(classroomLayout);
        classroomLayout.setHorizontalGroup(
            classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(classroomLayout.createSequentialGroup()
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(classroomLayout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(classroomLayout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addComponent(jLabel1)
                                .addGap(32, 32, 32)
                                .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(classroomLayout.createSequentialGroup()
                                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(mathButton)
                                    .addComponent(nameButton)
                                    .addComponent(room))
                                .addGap(18, 18, 18)
                                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(stuClass, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE)
                                    .addComponent(nameText)
                                    .addComponent(mathText))
                                .addGap(31, 31, 31)
                                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(classroomLayout.createSequentialGroup()
                                        .addComponent(sportButton)
                                        .addGap(18, 18, 18)
                                        .addComponent(sportText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(classroomLayout.createSequentialGroup()
                                        .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(javaButton)
                                            .addComponent(ageButton))
                                        .addGap(18, 18, 18)
                                        .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(ageText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(javaText, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
                    .addGroup(classroomLayout.createSequentialGroup()
                        .addGap(138, 138, 138)
                        .addComponent(jLabel2)))
                .addContainerGap(133, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, classroomLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(27, 27, 27)
                .addComponent(jButton2)
                .addGap(67, 67, 67))
        );
        classroomLayout.setVerticalGroup(
            classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(classroomLayout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(jLabel2)
                .addGap(31, 31, 31)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(room)
                    .addComponent(stuClass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ageButton)
                    .addComponent(ageText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameButton)
                    .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(javaButton)
                    .addComponent(javaText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(53, 53, 53)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mathButton)
                    .addComponent(mathText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sportButton)
                    .addComponent(sportText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
                .addGroup(classroomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addGap(50, 50, 50))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(classroom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(classroom, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       int stuId=Integer.valueOf(id.getText());
       Student stu=new Student();
       StudentSystemDao system=new StudentSystemDaoJDBCImpl();
       stu=system.findStudentById(stuId);
       if(room.isSelected())
       {
           String clazz=stuClass.getText();
           stu.setClazz(clazz);  
       }
       else if(ageButton.isSelected())
       {
           int stuAge=Integer.valueOf(ageText.getText());
           stu.setAge(stuAge);
       }
       else if(nameButton.isSelected())
       {
           String stuName=nameText.getText();
           stu.setName(stuName);
          
       }
       else if(javaButton.isSelected())
       {
           Double stuJava=Double.valueOf(javaText.getText());
           Course java=new Course("java",stuJava);
           stu.getCourseList().get(0).setScore(stuJava);
           
       }
       else if(mathButton.isSelected())
       {
            Double stuMath=Double.valueOf(mathText.getText());
           Course math=new Course("math",stuMath);
           stu.getCourseList().get(1).setScore(stuMath);
          
       }
       else if(sportButton.isSelected())
       {
            Double stuSport=Double.valueOf(sportText.getText());
           Course sport=new Course("sport",stuSport);
           stu.getCourseList().get(2).setScore(stuSport);
       }
       if(system.update(stu))
       {
            JOptionPane.showMessageDialog(this, "修改成功");
       }
       else
       {
            JOptionPane.showMessageDialog(this, "修改失败");
       }
       
    }//GEN-LAST:event_jButton1ActionPerformed

    private void mathButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mathButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mathButtonActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        TeacherMenu menu=new TeacherMenu();
        menu.setVisible(true);
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(UpdataFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new UpdataFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton ageButton;
    private javax.swing.JFormattedTextField ageText;
    private javax.swing.JPanel classroom;
    private javax.swing.JFormattedTextField id;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton javaButton;
    private javax.swing.JFormattedTextField javaText;
    private javax.swing.JRadioButton mathButton;
    private javax.swing.JFormattedTextField mathText;
    private javax.swing.JRadioButton nameButton;
    private javax.swing.JFormattedTextField nameText;
    private javax.swing.JRadioButton room;
    private javax.swing.JRadioButton sportButton;
    private javax.swing.JFormattedTextField sportText;
    private javax.swing.JFormattedTextField stuClass;
    // End of variables declaration//GEN-END:variables
}
